# 名称:zyl
# 时间2022/12/27  11:31

from appium.webdriver.common.mobileby import MobileBy as By
from pages.base_page import BasePage
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class AssertionsPage(BasePage):
    # 定位器

    # 断言设置定位器
    set_locator = (By.XPATH, '//android.widget.TextView[@resource-id=\"com.gfeng.daydaycook:id/mTitle\"]')

    # 个人资料定位器
    data_locator = (By.XPATH, '//android.widget.TextView[@resource-id=\"com.gfeng.daydaycook:id/mTitle\"]')

    # 保存成功定位器
    # save_locator = (By.XPATH, '//*[@text="{}"]'.format("修改成功"))
    save_locator = (By.XPATH, '//*[contains(@text,"{}")]'.format("修改成功"))
    # save_locator = (By.XPATH, '//android.widget.LinearLayout/android.view.View[1]')

    # 清空成功定位器
    empty_locator = (By.XPATH,'//android.widget.TextView[@resource-id=\"com.gfeng.daydaycook:id/cacheSizeTextView\"]')

    # 关闭接收消息通知定位器
    close_locator = (By.XPATH,'//*[contains(@text,"{}")]'.format("在已安装应用的列表中找不到该应用"))

    # 分享微信好友(朋友圈)定位器
    share_wechat = (By.XPATH, '//*[contains(@text,"{}")]'.format("请安装微信客户端"))

    # 分享新浪微博定位器
    share_weibo = (By.XPATH, '//*[contains(@text,"{}")]'.format("请安微博客户端"))

    # 复制链接定位器
    copy_link = (By.XPATH, '//*[contains(@text,"{}")]'.format("链接已复制"))

    # 关于我们定位器
    about_locator = (By.XPATH,'//android.widget.TextView[@resource-id=\"com.gfeng.daydaycook:id/mTitle\"]')

    # 获取设置文本
    def get_setting(self):
        return self.driver.find_element(*self.set_locator).text

    # 获取个人资料文本
    def get_data(self):
        return self.driver.find_element(*self.data_locator).text

    # 获取修改成功文本
    def get_save(self):
        wait = WebDriverWait(self.driver,5,0.5)
        element = wait.until(EC.presence_of_element_located(self.save_locator))
        return element.text

    # 获取清空成功文本
    def get_empty(self):
        return self.driver.find_element(*self.empty_locator).text

    # 获取关闭接收消息通知文本
    def get_receive(self):
        wait = WebDriverWait(self.driver, 5, 0.5)
        element = wait.until(EC.presence_of_element_located(self.close_locator))
        return element.text

    # 获取分享微信(朋友圈)文本
    def get_wechat(self):
        wait = WebDriverWait(self.driver, 5, 0.5)
        element = wait.until(EC.presence_of_element_located(self.share_wechat))
        return element.text

    # 获取新浪微博文本
    def get_weibo(self):
        wait = WebDriverWait(self.driver, 5, 0.5)
        element = wait.until(EC.presence_of_element_located(self.share_weibo))
        return element.text

    # 获取复制链接文本
    def get_link(self):
        wait = WebDriverWait(self.driver, 5, 0.5)
        element = wait.until(EC.presence_of_element_located(self.copy_link))
        return element.text

    # 获取关于我们文本
    def get_we(self):
        return self.driver.find_element(*self.about_locator).text


